package com.muse.mdc;

import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

/**
 * https://blog.csdn.net/chijiansong/article/details/127976573
 */
public class MdcTest {
    private static final String KEY = "requestId";
    private static final Logger logger = LoggerFactory.getLogger(MdcTest.class);

    public static void main(String[] args) {

        // 入口传入请求ID
        MDC.put(KEY, UUID.randomUUID().toString());

        // 打印日志
        logger.debug("log in main thread 1");
        logger.debug("log in main thread 2");
        logger.debug("log in main thread 3");

        // 出口移除请求ID
        MDC.remove(KEY);
    }
}
